/** 
 * @Title: DutyDAOImpl.java 
 * @Package com.prs.um.dutymanager.dao.impl 
 * @Description: 职务DAO
 * @author flybonew@163.com 
 * @date 2013-1-7 下午4:50:21 
 * @version V1.0 
 */  
package com.prs.um.dutymanager.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.prs.um.dutymanager.dao.DutyDAO;
import com.prs.um.dutymanager.dto.Duty;

/** 
 * @ClassName: DutyDAOImpl 
 * @Description: 职务的DAO实现类
 * @author flybonew@163.com
 * @date 2013-1-7 下午4:50:21 
 * 
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class DutyDAOImpl implements DutyDAO {
	
	@Resource
	private HibernateTemplate hibernateTemplate;
	
	/*
	 * @Description: 添加一个职务
	 * @author flybonew@163.com
	 * @date 2013-1-8 上午11:09:23 
	 */
	@Override
	public Duty addDuty(Duty duty) {
		this.hibernateTemplate.save(duty);
		return  duty;
	}

	/*
	 * @Description: 修改一个职务
	 * @author flybonew@163.com
	 * @date 2013-1-8 上午11:09:23 
	 */
	@Override
	public void updateDuty(Duty duty) {
		this.hibernateTemplate.update(duty);
	}

	/*
	 * @Description: 删除职务
	 * @author flybonew@163.com
	 * @date 2013-1-8 上午11:09:23 
	 */
	@Override
	public void deleteDuty(Duty duty) {
		this.hibernateTemplate.delete(duty);
	}

	/*
	 * @Description: 通过ID查询职务
	 * @author flybonew@163.com
	 * @date 2013-1-8 上午11:09:23 
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Duty selectDutyById(String dutyId) {
		StringBuffer sql = new StringBuffer();
		sql.append("from Duty where 1=1 ");
		sql.append("and id_ = '"+ dutyId+"'");
		final String typeSql = new String(sql);
		List<Duty> list = (List<Duty>)this.hibernateTemplate.find(typeSql);
		if(null != list && list.size() > 0){
			Duty duty = list.get(0);
			return duty;
		}
		return null;
	}
	
}
